<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>留言板</title>

    <!-- Bootstrap core CSS -->
    <link href="./Public/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap theme -->
    <link href="./Public/css/bootstrap-theme.min.css" rel="stylesheet">

    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    
  </head>

  <body>

    <!-- Fixed navbar -->
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li role="separator" class="divider"></li>
                <li class="dropdown-header">Nav header</li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>

            
          </ul>

          <?php if(isset($_SESSION['nickname'])){ ?>

          <ul class="navbar-form navbar-right">
            <li class="btn btn-success"><?php echo $_SESSION['nickname'] ?></li>
            <li class="btn btn-success"><a style="color:#fff" href="./index.php?m=index&c=user&a=loginout">退出</a></li>
          </ul>

          <?php  }else{ ?>

          <ul class="navbar-form navbar-right">
            <li class="btn btn-success"><a style="color:#fff" href="./index.php?m=index&c=user&a=reg">注册</a></li>
            <li class="btn btn-success"><a style="color:#fff" href="./index.php?m=index&c=user&a=login">登录</a></li>
          </ul>


          <?php   } ?>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="container theme-showcase" role="main" style="padding-top:100px">

      <!-- Main jumbotron for a primary marketing message or call to action -->
      <div class="jumbotron">
        <?php foreach ($msgs as $key => $row) { ?>

        <div class="alert alert-success" role="alert">
          <strong><?php echo $row['nickname']; ?>:</strong><?php echo $row['content']; ?>（<?php echo Ftime($row['ctime']); ?>）

          <a href="./edit.php?id=<?php echo $key ?>" class="btn btn-info">修改</a>
          <button data-id=<?php echo $key ?> class="btn btn-danger delbtn">删除</button>
        </div>

        <?php } ?>
      <form  action="./index.php?m=index&c=index&a=add" method="post" class="form-block">
      <div class=" form-inline form-group">
        <div class="input-group">
          <div class="input-group-addon">用户名</div>
          <input type="text"  class="form-control" id="exampleInputAmount" placeholder="<?php echo isset($_SESSION['nickname']) ? $_SESSION['nickname'] :''; ?>" disabled >
        </div>
        <button type="submit" class="btn btn-success">发布</button>
      </div>
      <div class="form-block" style="margin-top:10px">
      <textarea name="content" style="width:100%" class="form-control" rows="3"></textarea>
      </div>

      
      
    </form>
      </div>
    </div>


    </div> 
  </body>
  <script type="text/javascript">

      $(function  () {
        

          $('.delbtn').click(function(event) {
              data_id = $(this).attr('data-id');
              that = $(this);
              $.ajax({
                url: './ajaxdel.php',
                type: 'POST',
                dataType: 'json',
                data: {id: data_id},
              })
              .done(function(res) {
                  
                  if(res.error==0){
                    alert(res.info);

                    that.parent().remove();
                  }else{
                     alert(res.info);
                  }
              })
              .fail(function() {
                console.log("error");
              })
              
          });
      })
  </script>
</html>
